<?php

/**
 * loan actions.
 *
 * @package    vmdai
 * @subpackage loan
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class loanActions extends sfActions
{
    
        public function executeCaptcha(sfWebRequest $request)  {
            $img = new securimage();
            $img->image_width = 125;
            $img->image_height = 35;
            $img->gd_font_size = 12;
            $img->perturbation = 0.9;
            $img->code_length = 4;
            $img->image_bg_color = new Securimage_Color("#ffffff");
            $img->use_transparent_text = true;
            $img->text_transparency_percentage = 60; // 100 = completely transparent
            $img->num_lines = 1;
            $img->text_angle_minimum = 0;
            $img->image_signature = '';
            $img->session_name = '';
            $img->text_color = new Securimage_Color("#000000");
            $img->line_color = new Securimage_Color("#cccccc");
            $img->session_space = 'housing';
            return $img->show();
    }
    
    public function executeList(sfWebRequest $reques){
      $this->getResponse()->setTitle("我要融资-微美贷VMdai官网_中国领先的互联网金融P2P网贷平台_网络贷款_投资理财");
        
    }
    
    public function executeHouseinfo(sfWebRequest $reques){
        
    }
    
    
    
    /**
    * Executes index action
    *
    * @param sfRequest $request A request object
    */
    public function executeHousing(sfWebRequest $request){
      $this->getResponse()->setTitle("房产抵押贷_个人小额借款_微美贷Vmdai");
        if( $request->isMethod("POST") ) {
             $code = $request->getPostParameter('validatorCode');
             
            $current_code = $this->getUser()->getAttribute('securimage_code_value','','housing');
            if( strtolower($code) !=  $current_code ){
                $this->getUser()->setFlash('error', '验证码输入错误！请重新输入');
                $this->redirect('loan/housing');
            }
            
            $this->getUser()->setAttribute('code','','housing');
            $contact_name = trim($request->getParameter("Contact"));            
            $mobile = trim($request->getParameter("Mobile"));     
            $amount = trim($request->getParameter("Amount"));  
            $area = trim($request->getParameter("Area"));  
            
            $floor_space = trim($request->getParameter("HousingArea"));//平方米
            $house_age = trim($request->getParameter("HousingAge"));
            $community = trim($request->getParameter("Village")); //小区
            
            $deadline = trim($request->getParameter("Period"));//期限
            $remark = trim($request->getParameter("Remark")); //备注
            
            if(empty ($contact_name)){
                $this->getUser()->setFlash('error', '联系人不能为空');
                $this->redirect('loan/housing');
            }
            if(empty ($mobile)){
                $this->getUser()->setFlash('error', '手机号码不能为空');
                $this->redirect('loan/housing');
            }
            if(empty ($amount)){
                $this->getUser()->setFlash('error', '意向融资金额不能为空');
                $this->redirect('loan/housing');
            }
            if(empty ($area)){
                $this->getUser()->setFlash('error', '所在区域不能为空');
                $this->redirect('loan/housing');
            }
            if(empty ($floor_space)){
                $this->getUser()->setFlash('error', '房屋面积不能为空');
                $this->redirect('loan/housing');
            }
            if(empty ($house_age)){
                $this->getUser()->setFlash('error', '房龄不能为空');
                $this->redirect('loan/housing');
            }
            if(empty ($community)){
                $this->getUser()->setFlash('error', '所在小区不能为空');
                $this->redirect('loan/housing');
            }
            if(empty ($deadline)){
                $this->getUser()->setFlash('error', '预期融资期限不能为空');
                $this->redirect('loan/housing');
            }
            
            $user_id = $this->getUser()->getAttribute("user_id");
            $user_house_model = new UserHouseLoan;
            $user_house_model->setContactName($contact_name)
                             ->setMobile($mobile)
                             ->setAmount($amount)
                             ->setArea($area)
                             ->setFloorSpace($floor_space)
                             ->setHouseAge($house_age)
                             ->setCommunity($community)
                             ->setDeadline($deadline)
                             ->setUserId($user_id)
                             ->setRemark($remark)
                             ->save();
            
            
            
            
        }

    }
    
    
  
}
